CREATE TABLE [dbo].[tb_FuentesDeFinanciamiento]
(
[idFuenteFinanciamiento] [int] NOT NULL IDENTITY(1, 1),
[Descripcion] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[updatetb_FuentesDeFinanciamiento] ON [dbo].[tb_FuentesDeFinanciamiento]
 FOR UPDATE AS 
 IF (update(idFuenteFinanciamiento)) begin 
	 SELECT * FROM inserted 
	 IF @@ROWCOUNT = 1 begin 
		 UPDATE tb_Plazas
		 SET Financiamiento = (SELECT idFuenteFinanciamiento FROM inserted)
		 WHERE tb_Plazas.Financiamiento = (SELECT idFuenteFinanciamiento FROM deleted)
		 UPDATE tb_Servicios
		 SET Financiamiento = (SELECT idFuenteFinanciamiento FROM inserted)
		 WHERE tb_Servicios.Financiamiento = (SELECT idFuenteFinanciamiento FROM deleted)
		 UPDATE tb_AperturasDeReestructura
		 SET Financiamiento = (SELECT idFuenteFinanciamiento FROM inserted)
		 WHERE tb_AperturasDeReestructura.Financiamiento = (SELECT idFuenteFinanciamiento FROM deleted)
		 UPDATE tb_Edificios
		 SET FinalidadOriginal = (SELECT idFuenteFinanciamiento FROM inserted)
		 WHERE tb_Edificios.FinalidadOriginal = (SELECT idFuenteFinanciamiento FROM deleted)
		 UPDATE tb_FuncionesLUI
		 SET Financiamiento = (SELECT idFuenteFinanciamiento FROM inserted)
		 WHERE tb_FuncionesLUI.Financiamiento = (SELECT idFuenteFinanciamiento FROM deleted)
	end  ELSE begin 
		 ROLLBACK TRANSACTION 
 end 
 end
GO
ALTER TABLE [dbo].[tb_FuentesDeFinanciamiento] ADD CONSTRAINT [PK_tb_FuentesDeFinanciamiento] PRIMARY KEY NONCLUSTERED  ([idFuenteFinanciamiento]) ON [PRIMARY]
GO
